﻿using System;
using LuaBoardPlugin;
using LuaInterface;
using System.Management;

namespace ManagementObj
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class PlugIn : IPlugin
    {
        private string m_strName;
        private IPluginHost m_Host;

        public PlugIn()
        {
            m_strName = "ManagementObj";
        }


        public string Name
        { get { return m_strName; } set { m_strName = value; } }

        public IPluginHost Host
        {
            get { return m_Host; }
            set
            {
                m_Host = value;
                //m_Host.Register(this);
            }
        }
        public void RegisterLuaFunction(Lua lua)
        {
            lua.RegisterFunction("GetCPUNumberOfCores", this, this.GetType().GetMethod("GetCPUNumberOfCores"));
        }

        public uint GetCPUNumberOfCores()
        {
            uint number = 0;
            ManagementObjectSearcher moSearch = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
            foreach (ManagementObject mObject in moSearch.Get())
            {
                number += (uint)mObject["NumberOfCores"];
            }
            return number;
        }

    }
}
